/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SLE_CONNECT_SERVICE_H
#define SLE_CONNECT_SERVICE_H

#include <memory>
#include <vector>
#include "sle_address_parcel.h"
#include "sle_connect_parcel.h"
#include "sle_connect_config.h"
#include "sle_connect_config_manager.h"
#include "sle_error_code.h"

namespace OHOS {
namespace NearLink {
namespace SleStandard {
class IConnectCallback {
public:
    virtual ~IConnectCallback() = default;
    virtual void OnConnectStateChange(uint16_t connectId, const SleAddress &address, SleConnectState state,
        SlePairState pairState, SleDisConnectReason reason) = 0;
    virtual void OnConnectParameterUpdate(uint16_t connectId, const SleConnectParam &param, SleErrorCode errCode) = 0;
    virtual void OnConnectParamUpdateComplete(
        uint16_t connectId, const SleConnectionParamUpdateEvt &param, SleErrorCode errCode) = 0;
    virtual void OnAuthComplete(
        uint16_t connectId, const SleAddress &address, const SleAuthInfo &info, SleErrorCode errCode) = 0;
    virtual void OnPairComplete(uint16_t connectId, const SleAddress &address, SleErrorCode errCode) = 0;
    virtual void OnReadRssiComplete(uint16_t connectId, int8_t rssi, SleErrorCode errCode) = 0;
};

class SleConnectService {
public:
    SleConnectService();
    ~SleConnectService();

    static SleConnectService *GetInstance();
    SleErrorCode Connect(const SleAddress &address);
    SleErrorCode Disconnect(const SleAddress &address);
    SleErrorCode UpdateConnectParam(uint16_t connectId, const SleConnectParam *param);
    SleErrorCode SendPairRequest(const SleAddress &address);
    SleErrorCode RemovePairedDevice(const SleAddress &address);
    SleErrorCode RemoveAllPairedDevices();
    SleErrorCode GetPairedDevicesNum(uint16_t &number);
    SleErrorCode GetPairedDevices(std::vector<SleAddress> &devices, uint16_t &number);
    SleErrorCode GetPairState(const SleAddress &address, uint8_t &state);
    SleErrorCode ReadRemoteRssi(uint16_t connectId);
    SleErrorCode SetDefaultConnParam(const SleDefaultConnectionParam &defaultConnParam);
    SleErrorCode RegisterConnectCallback(IConnectCallback &callback);
    SleErrorCode UnregisterConnectCallback(IConnectCallback &callback);
    std::unique_ptr<SleConnectConfigManager> connCfgMgr_;
private:
    class SleConnectServiceCallback;
    std::unique_ptr<SleConnectServiceCallback> serviceCallback_;
    IConnectCallback *callback_ = nullptr;
    SleConnectConfig connectConfig_;
};
} // SleStandard
} // NearLink
} // OHOS

#endif // SLE_CONNECTION_SERVICE_H